﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace 获取字形索引
{
    internal class Program
    {
        static void Main(string[] args)
        {

            try
            {
                // 创建 GlyphTypeface 对象，指定字体文件路径
                GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri(@"file:///C:/WINDOWS/FONTS/SIMSUN.TTC"));

                // 要查询的文本
                //string text = "内操关闭四路炉管进料控制阀MF";
                string imput = Console.ReadLine();
                while (imput != null)
                {
                    // 遍历文本中的每个字符
                    foreach (char c in imput)
                    {
                        // 检查字符是否存在于字体的映射中
                        if (glyphTypeface.CharacterToGlyphMap.TryGetValue(c, out ushort glyphIndex))
                        {
                            Console.WriteLine($"字符 '{c}' 的字形索引是: {glyphIndex}");
                        }
                        else
                        {
                            Console.WriteLine($"字体中不存在字符 '{c}' 的字形索引。");
                        }
                    }
                    imput = Console.ReadLine();
                }
               
            }
            catch (Exception ex)
            {
                Console.WriteLine($"发生错误: {ex.Message}");
            }
        }
    }
}
